package crack;

import org.junit.Test;

/**
 * @author fance
 * @date 18-4-12 上午9:22
 */
public class Bits {
    // n & (n - 1)
    public int cntOne(int n) {
        int cnt = 0;
        while (n > 0) {
            cnt++;
            n = n & (n - 1);
        }
        return cnt;
    }
    public int bitSwapRequired(int a, int b) {
        int cnt = 0;
        int xor = a ^ b;
        return cntOne(xor);
    }

    @Test
    public void test() {
        System.out.println(bitSwapRequired(2, 1));
    }

}
